package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * @author gengjian
     * @date 2025/02/26 09:17:16
     * 专辑上架
     */
    @Operation(summary = "专辑上架")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        //调用服务层
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * @author gengjian
     * @date 2025/02/26 09:17:16
     * 专辑下架
     */
    @Operation(summary = "专辑下架")
    @GetMapping("/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        //调用服务层
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }
    /**
     * @author gengjian
     * @date 2025/02/27 17:40:28
     * 批量上传
     */
    @Operation(summary = "批量上架")
    @GetMapping("/batchUpperAlbum")
    public Result batchUpperAlbum(){
        for (long i = 1; i <= 1617; i++) {
            searchService.upperAlbum(i);
        }
        return Result.ok();
    }

    /**
     * @author gengjian
     * @date 2025/02/26 10:33:46
     * 关键词或分类检索
     */
    @Operation(summary = "关键词或分类检索")
    @PostMapping("")
    public Result search(@RequestBody AlbumIndexQuery albumIndexQuery){
        //调用服务层方法
        //返回数据
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    /**
     * @author gengjian
     * @date 2025/03/02 15:35:49
     * 根据一级分类id查频道列表数据
     */
    @Operation(summary = "根据一级分类id查频道列表数据")
    @GetMapping("/channel/{category1Id}")
    public Result channel(@PathVariable("category1Id")Long category1Id){
        //调用服务层方法
        List<Map<String,Object>> list = searchService.channel(category1Id);
        return Result.ok(list);
    }

    /**
     * 自动补全功能
     * @param keyword
     * @return
     */
    @Operation(summary = "关键字自动补全")
    @GetMapping("completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable String keyword) {
        //  根据关键词查询补全
        List<String> list = searchService.completeSuggest(keyword);
        //  返回数据
        return Result.ok(list);
    }

    /**
     * @author gengjian
     * @date 2025/03/01 09:48:26
     * 根据专辑id查询专辑详情
     */
    @TsLogin(requiredLogin = false)
    @Operation(summary = "根据专辑id查询专辑详情")
    @GetMapping("/{albumId}")
    public Result findAlbumDetail(@PathVariable Long albumId){
        //调用服务层方法
        Map<String,Object> map = searchService.findAlbumDetail(albumId);
        return Result.ok(map);
    }


}

